package org.lagou.demo.controller;

import org.lagou.demo.service.IDemoService;
import org.lagou.edu.mvcframework.annotations.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@JyController
@JyRequestMapping("/demo")
@JySecurity("level1")
public class DemoController {

    @JyAutowired
    private IDemoService iDemoService;

    @JyRequestMapping("/query")
    public String query(HttpServletRequest req, HttpServletResponse resp, String name) {

        return iDemoService.getName(name);

    }

    @JyRequestMapping("/security1")
    // @JySecurity()
    public String security1(HttpServletRequest req, HttpServletResponse resp, String name) {

        return iDemoService.getName(name);

    }

    @JyRequestMapping("/security11")
    // @JySecurity()
    public String security11(HttpServletRequest req, HttpServletResponse resp, String accessName) throws IOException {

        resp.getWriter().write("Hello," + accessName);
        return iDemoService.getName(accessName);

    }

    @JyRequestMapping("/security2")
    @JySecurity("level2")
    public String security2(HttpServletRequest req, HttpServletResponse resp, String accessName) throws IOException {

        resp.getWriter().write("Hello," + accessName);
        return iDemoService.getName(accessName);

    }

    @JyRequestMapping("/security3")
    @JySecurity("level3")
    public String security3(HttpServletRequest req, HttpServletResponse resp, String accessName) throws IOException {

        resp.getWriter().write("Hello," + accessName);
        return iDemoService.getName(accessName);

    }
}
